package com.skyjing.askit.dsl.edittext

import android.text.TextWatcher
import android.widget.EditText
import androidx.appcompat.widget.AppCompatEditText

/**
 * 参数TextWatcherDsl.() -> Unit，TextWatcherDsl是我们刚刚自定义的类，然后后面跟了一个点，
 * 就是说，这个参数可以接收TextWatcherDsl类里的所有方法，只要是它里面的方法都可以传递进来。
 */
inline fun EditText.onTextListenerInline (textWatcherDsl: TextWatcherDsl.()->Unit) : TextWatcher{
    val textWatcher = TextWatcherDsl().apply(textWatcherDsl)
    addTextChangedListener(textWatcher)
    return textWatcher
}

infix fun EditText.onTextListenerInfix(textWatcherDsl: TextWatcherDsl.()->Unit) : TextWatcher{
    val textWatcher = TextWatcherDsl().apply(textWatcherDsl)
    addTextChangedListener(textWatcher)
    return textWatcher
}

inline fun AppCompatEditText.onTextListenerInline(textWatcherDsl: TextWatcherDsl.()->Unit) : TextWatcher{
    val textWatcher = TextWatcherDsl().apply(textWatcherDsl)
    addTextChangedListener(textWatcher)
    return textWatcher
}

infix fun AppCompatEditText.onTextListenerInfix(textWatcherDsl: TextWatcherDsl.()->Unit) : TextWatcher{
    val textWatcher = TextWatcherDsl().apply(textWatcherDsl)
    addTextChangedListener(textWatcher)
    return textWatcher
}
